#ifndef  VSSHADERFUNCTION_H
#define  VSSHADERFUNCTION_H
#include "VSObject.h"
#include "VSPutNode.h"
#include "VSName.h"
namespace VSEngine2
{
	class VSMaterial;
	class VSStream;
	class VSGRAPHIC_API VSShaderFunction : public VSObject
	{
		//RTTI
		DECLARE_RTTI;
		DECLARE_INITIAL_NO_CLASS_FACTORY;
	public:
		virtual ~VSShaderFunction() = 0;
	protected:
		VSUsedName m_ShowName;
		VSShaderFunction(const VSUsedName & ShowName,VSMaterial * pMaterial);
		VSShaderFunction();
		VSArray<VSInputNode *> m_pInput;
		VSArray<VSOutputNode *> m_pOutput;
		VSMaterial * m_pOwner;
		bool m_bIsVisited;
		inline void SetOwner(VSMaterial * pOwner)
		{
			VSMAC_ASSERT(pOwner);
			m_pOwner = pOwner;
		}
		void AddAllPutNodeTo(VSArray<VSPutNode *>& LinkArray);
		bool Link(const VSArray<VSPutNode *>& OldLink,const VSArray<VSPutNode *>& NewLink);
	public:
		friend class VSMaterial;
		//protected:
		
		virtual unsigned int DiskUse()const;

		virtual bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		virtual bool Load(VSStream & rStream,unsigned int &iSaveUse);
		virtual bool Register(VSStream & rStream)const;
		virtual bool Link(VSStream & rStream);
	public:
		virtual bool Clone(const VSObject *pObject,unsigned int uiType);

		virtual bool GetInputValueString(VSString &OutString)const;
		virtual bool GetOutPutValueString(VSString &OutString)const;
		virtual bool GetFuntionString(VSString &OutString)const = 0;
		bool GetShaderTreeString(VSString &OutString);
		bool ClearShaderTreeStringFlag();
		

		VSInputNode * GetInputNode(unsigned int uiNodeID)const;
		VSInputNode * GetInputNode(const VSString & NodeName)const;
		inline unsigned int GetInputNodeNum()const
		{
			return m_pInput.GetNum();
		}
		VSOutputNode * GetOutputNode(unsigned int uiNodeID)const;
		VSOutputNode * GetOutputNode(const VSString & NodeName)const;
		inline unsigned int GetOutputNodeNum()const
		{
			return m_pOutput.GetNum();
		}
		inline const VSUsedName & GetShowName()const
		{
			return m_ShowName;
		}

		VSString GetValueEqualString(const VSOutputNode * pOutPutNode,const VSInputNode * pInputNode)const;
	};
	DECLARE_Ptr(VSShaderFunction);
	VSTYPE_MARCO(VSShaderFunction);
}
#endif